package com.itlaobing.dev;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 1、通过实现 javax.servlet.Servlet接口的方式开发一个 Servlet类 (servlet-class)
 * 2、在 javax.servlet.Servlet 接口中声明的5个方法都是实例方法
 */
public class PrimitiveServlet implements Servlet {
	
	private ServletConfig config ;

	@Override
	public void init(ServletConfig config) throws ServletException {
		this.config = config ;
	}

	@Override
	public void service( ServletRequest req , ServletResponse resp ) throws ServletException, IOException {
		
		// 获得可以"向客户端输出数据"的字符打印流
		PrintWriter out = resp.getWriter();
		
		out.println( "<div>" );
		out.println( LocalDateTime.now() );
		out.println( "</div>" );
		
		out.println( "<div>" );
		out.println( this );
		out.println( "</div>" );
		
		out.println( "<div>" );
		out.println( Thread.currentThread() );
		out.println( "</div>" );
		
		out.println( "<div>" );
		out.println( this.getClass().getClassLoader() );
		out.println( "</div>" );
		
	}
	
	@Override
	public void destroy() {
	}

	@Override
	public ServletConfig getServletConfig() {
		return this.config;
	}

	@Override
	public String getServletInfo() {
		return "";
	}

}
